package cn.stronglink.assetmanage.business.inspection.view.repair;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.inspection.adapter.RepairAdapter;
import cn.stronglink.assetmanage.business.inspection.view.repairDetail.RepairDetailFragment;
import cn.stronglink.assetmanage.business.inspection.view.resiger.RepairRegisterFragment;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.assetmanage.utils.ToastUtil;
import cn.stronglink.assetmanage.widget.CustomProgressDialog;

/**
 * 操作维修单fragment
 * Created by zhengjinglan on 2018/6/21.
 */

public class RepairView {
    private Fragment fragment;
    //表单列表
    @BindView(R.id.rv_repair_list)
    RecyclerView rv_repair_list;
    Dialog mDialog;
    //表单列表adapter
    private RepairAdapter listadapter;

    public RepairView(Fragment fragment, View view, RepairAdapter repairAdapter){
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        this.listadapter = repairAdapter;
    }


    /**
     * 设置表单列表数据
     */
    public void setListData(final List<Repair> listData){
        if (listadapter != null){
            this.getFragment().getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    listadapter.notifyDatasChanged(listData);
                }
            });

        }
    }

    public Fragment getFragment() {
        return fragment;
    }

    public void showOrderDetail(String repair_id){

        MainActivity activity = (MainActivity)this.getFragment(). getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setFragment(new RepairRegisterFragment());
        pe.setPosition(MainActivity.FRAGMENT_REPAIR_REGITER_ID);
        pe.setTitle("资产详情");
        // 设置打开盘点详情后传递的参数
        Bundle bundle=new Bundle();
        bundle.putSerializable(Constants.SEARCH_REPAIR_NO, repair_id);
        pe.setBundle(bundle);
        activity.onEventRegister(pe);
    }

    public void showProgressDialog(String msg){
        mDialog = CustomProgressDialog.createLoadingDialog(fragment.getActivity(), msg);
        mDialog.setCancelable(false);
        mDialog.show();
    }

    public void hideProgressDialog(){
        if(mDialog!=null){
            mDialog.cancel();
        }
    }

}
